package com.bootdo.wx.service.impl;

import com.bootdo.common.utils.PageHelperUtils;
import com.bootdo.wx.dao.CmsSlideDao;
import com.bootdo.wx.dao.GoodsUpgradeDao;
import com.bootdo.wx.dao.MemberUserDao;
import com.bootdo.wx.domain.GoodsUpgradeDO;
import com.bootdo.wx.domain.MemberUserDO;
import com.bootdo.wx.service.GoodsUpgradeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class GoodsUpgradeServiceImpl implements GoodsUpgradeService {
	@Autowired
	private GoodsUpgradeDao goodsUpgradeDao;
	@Autowired
	private CmsSlideDao cmsSlideDao;
	@Autowired
	private MemberUserDao memberUserDao;
	
	@Override
	public GoodsUpgradeDO get(String id){
		return goodsUpgradeDao.get(id);
	}
	
	@Override
	public List<GoodsUpgradeDO> list(Map<String, Object> map){
		return goodsUpgradeDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return goodsUpgradeDao.count(map);
	}
	
	@Override
	public int save(GoodsUpgradeDO goodsUpgrade){
		return goodsUpgradeDao.save(goodsUpgrade);
	}
	
	@Override
	public int update(GoodsUpgradeDO goodsUpgrade){
		return goodsUpgradeDao.update(goodsUpgrade);
	}
	
	@Override
	public int remove(String id){
		return goodsUpgradeDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return goodsUpgradeDao.batchRemove(ids);
	}


	/*app查询列表*/
	@Override
	public PageInfo<Map<String,Object>> getUpgradeGoodsList(Map<String, Object> paramMap) {
		String userId = com.bootdo.common.utils.StringUtils.getString(paramMap.get("userId"));
		MemberUserDO memberUserDO = memberUserDao.get(userId);
		int level = 0;
		if (memberUserDO != null) {
			paramMap.put("level", memberUserDO.getLevel());
			level = memberUserDO.getLevel();
		} else {
			paramMap.put("level", 0);
			level = 0;
		}
		PageHelperUtils.page(paramMap);
		List<Map<String,Object>> goodsList =goodsUpgradeDao.getUpgradeGoodsList(paramMap);
		for (Map<String, Object> goodsMap : goodsList) {
			int isvip = Integer.valueOf(goodsMap.get("isvip").toString());
			String imgurl = goodsMap.get("imgurl").toString();
			List<String> imgList = new ArrayList<String>();
			imgList.add(imgurl);
			goodsMap.remove("imgurl");
			goodsMap.put("imgList",imgList);
		}
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(goodsList);
		return pageInfo;
	}

	/*后台查询会员专区列表*/
	@Override
	public List<Map<String,Object>> getUpgradeList(Map<String, Object> map) {
		return goodsUpgradeDao.getUpgradeList(map);
	}

	@Override
	public int getUpgradeListCount(Map<String, Object> map) {
		return goodsUpgradeDao.getUpgradeListCount(map);
	}


	
}
